//productListForm
$.commonValidator_prodpricemaintain = function(){
	$("#productListForm").validate(
		{
			debug:false,
			rules:{
				tax_unit_price:{
					required:true,
					number:true
				},
				tax_free_unit_price:{
					required:true,
					number:true
				},
				tax_rate:{
					required:true,
					number:true
				},
				valid_date:{
					required:true
				},
				invalid_date:{
					required:true
				}
			},
			messages:{
				tax_unit_price:{
					required: getLanMsg("0ec22200-000070"),
					number:getLanMsg("0ec22200-000071")
				},
				tax_free_unit_price:{
					required:getLanMsg("0ec22200-000070"),
					number:getLanMsg("0ec22200-000071")
				},
				tax_rate:{
					required:getLanMsg("0ec22200-000070"),
					number:getLanMsg("0ec22200-000071")
				},
				valid_date:{
					required:getLanMsg("0ec22200-000070")
				},
				invalid_date:{
					required:getLanMsg("0ec22200-000070")
				}
			}
		}
	);
}

var ProdpriceMaintain = function() {
	var price_digit = 8;
	
	// 查询
	var queryFunction = function() {
		$("#queryProdPriceList").bind(
				'click',
				function() {
					$("#prodQueryForm").attr("action",
							ebvp_context + "/prodprice/queryprodpricebycond");
					$("#prodQueryForm").submit();
				});
	}

	// 清空
	var cancelFunction = function() {
		$("#queryCancel").bind('click', function() {
			$("#prodQueryForm").find("input").each(function() {
				$(this).val("");
			});
			$("#").submit();
		});
	}
	// trim
	function trim(strToTrim) {
		result = strToTrim
		for (_i = 0; _i < strToTrim.length; _i++) {
			if (strToTrim.charAt(_i) == " ")
				result = strToTrim.substr(_i + 1)
			else
				_i = strToTrim.length
		}
		strToTrim = result
		for (_i = strToTrim.length - 1; _i >= 0; _i--) {
			if (strToTrim.charAt(_i) == " ")
				result = strToTrim.substr(0, _i)
			else
				_i = 0
		}
		return result
	}

	function validatorData(obj) {
		// 先把非数字的都替换掉，除了数字和.
		obj.val(obj.val().replace(/[^\d.]/g, ""));
		// 必须保证第一个为数字而不是.
		obj.val(obj.val().replace(/^\./g, ""));
		// 保证只有出现一个.而没有多个.
		obj.val(obj.val().replace(/\.{2,}/g, "."));
		// 保证.只出现一次，而不能出现两次以上
		obj.val(obj.val().replace(".", "$#$").replace(/\./g, "").replace("$#$",
				"."));
		if (parseFloat(obj.val()) <= 0) {
			obj.val(1);
		}
		if (obj.val() != null && obj.val() != undefined && obj.val() != ""
				&& parseFloat(obj.val()) >= 0) {
			return true;
		} else {
			obj.val(1);
			return false;
		}
	}

	
	// 初始化单位和生产厂商
	function initUnitAndManufacure(trNode) {
		var pk_prod_v_value = "";
		var pk_prod_v_ele = trNode.find("[name='pk_prod_v']");
		if (pk_prod_v_ele != null) {
			pk_prod_v_value = pk_prod_v_ele.val();
		}
		var myts = new Date();
		jQuery.ajax( {
			type : "GET",
			async : false,
			url : ebvp_context + "/prodprice/queryUnitByPkProdV?pk_prod_v="
					+ pk_prod_v_value + "&myts=" + myts,
			dataType : "text",
			success : function(result) {
				var ele_pk_unit = trNode.find("[name='pk_unit']");
				if (result == 'NULL') {
					ele_pk_unit.empty();
				} else {
					var unitArray = eval("(" + result + ")");
					var unitValue = trNode.find("[name='pk_unit']").val();
					ele_pk_unit.empty();
					for ( var index = 0; index < unitArray.length; index++) {
						var obj = unitArray[index];
						if (unitValue == obj.pk_unit) {
							ele_pk_unit.append("<option value='" + obj.pk_unit
									+ "' selected>" + obj.name + "</option>");
						} else {
							ele_pk_unit.append("<option value='" + obj.pk_unit
									+ "'>" + obj.name + "</option>");
						}
					}
				}
			}
		})

		jQuery
				.ajax( {
					type : "GET",
					async : false,
					url : ebvp_context
							+ "/prodprice/queryManufactureByPkProdV?pk_prod_v="
							+ pk_prod_v_value + "&myts=" + myts,
					dataType : "text",
					success : function(result1) {
						var ele_pk_manufactory = trNode
								.find("[name='pk_manufactory']");
						if (result1 == 'NULL') {
							ele_pk_manufactory.empty();
						} else {

							var manufValue = trNode.find(
									"[name='pk_manufactory']").val();
							var manufactArray = eval("(" + result1 + ")");
							ele_pk_manufactory.empty();
							for ( var index = 0; index < manufactArray.length; index++) {
								var obj = manufactArray[index];
								if (manufValue == obj.pk_manufacture) {
									ele_pk_manufactory.append("<option value='"
											+ obj.pk_manufacture
											+ "' selected>" + obj.name
											+ "</option>");
								} else {
									ele_pk_manufactory.append("<option value='"
											+ obj.pk_manufacture + "'>"
											+ obj.name + "</option>");
								}
							}
						}
					}
				})
	}
	// 初始化币种
	function initCurrency(trNode) {
		var myts = new Date();
		jQuery.ajax( {
			type : "GET",
			async : false,
			url : ebvp_context + "/prodprice/queryCurrency?myts=" + myts,
			dataType : "text",
			success : function(result) {
				var ele_pk_currency = trNode.find("[name='pk_currency']");
				if (result == 'NULL') {
					ele_pk_currency.empty();
				} else {

					var cnyValue = ele_pk_currency.val();
					var cnyArray = eval("(" + result + ")");
					ele_pk_currency.empty();
					for ( var index = 0; index < cnyArray.length; index++) {
						var obj = cnyArray[index];
						if (cnyValue == obj.pk_currtype) {
							ele_pk_currency.append("<option value='"
									+ obj.pk_currtype + "' selected>"
									+ obj.name + "</option>");
						} else {
							ele_pk_currency.append("<option value='"
									+ obj.pk_currtype + "'>" + obj.name
									+ "</option>");
						}
					}
				}
			}
		})
	}

	function initTransport(trNode) {
		var myts = new Date();
		jQuery
				.ajax( {
					type : "GET",
					async : false,
					url : ebvp_context + "/prodprice/queryTransport?myts="
							+ myts,
					dataType : "text",
					success : function(result) {
						var ele_pk_transport = trNode
								.find("[name='pk_transport_type']");
						if (result == 'NULL') {
							ele_pk_transport.empty();
						} else {

							var transpVal = ele_pk_transport.val();
							var transportArray = eval("(" + result + ")");
							ele_pk_transport.empty();
							for ( var index = 0; index < transportArray.length; index++) {
								var obj = transportArray[index];
								if (transpVal == obj.pk_transporttype) {
									ele_pk_transport.append("<option value='"
											+ obj.pk_transporttype
											+ "' selected>" + obj.name
											+ "</option>");
								} else {
									ele_pk_transport.append("<option value='"
											+ obj.pk_transporttype + "'>"
											+ obj.name + "</option>");
								}
							}

						}
					}
				})
	}

	//翻页的脚本延续上一版本的写法，写到了jsp中
	// 下一页
//  var nextPageFunction = function() {
//		$("#nextPageBtn").bind(
//				'click',
//				function() {
//					$("#prodQueryForm").attr("action",
//							ebvp_context + "/prodprice/queryprodpricebycond");
//					$("#pageno").val(pDownIndex);
//					$("#prodQueryForm").submit();
//				});
//	}
//	// 上一页
//	var lastPageFunction = function() {
//		$("#lastPageBtn").bind(
//				'click',
//				function() {
//					$("#prodQueryForm").attr("action",
//							ebvp_context + "/prodprice/queryprodpricebycond");
//					$("#pageno").val(pUpInex);
//					$("#prodQueryForm").submit();
//				});
//	}
//
//	// 第n页
//	var nPageFunction = function() {
//		$("[name='nPageBtn']").bind(
//				'click',
//				function() {
//					$("#prodQueryForm").attr("action",
//							ebvp_context + "/prodprice/queryprodpricebycond");
//					$("#pageno").val($(this).attr("id")); // 把页码n定义成id
//					$("#prodQueryForm").submit();
//				});
//	}

	// 初始化价格精度
	var initPriceDigit = function() {
		$(document).ready(
				function() {
					var myts = new Date();
					jQuery.ajax( {
						type : "GET",
						async : false,
						url : ebvp_context
								+ "/prodprice/queryPriceScaleDigit?myts="
								+ myts,
						dataType : "text",
						success : function(result) {
							price_digit = result;
						}
					})
				});
	}

	// 截去多余的小数位数或者补足小数位
	function subReduNum(obj, intPrecision) {
		var strValue = obj.val();
		if (isNaN(strValue)) {
			return;
		}
		if (strValue == null || strValue == "") {
			return;
		}
		if (strValue.indexOf(".") != -1) {
			var values = strValue.split(".");
			if (values[1].length > intPrecision) {
				if (intPrecision > 0) {
					strValue = values[0] + "."
							+ values[1].substring(0, intPrecision);
					strValue = roundNum(strValue, values[1]
							.substring(intPrecision), intPrecision);
				} else {
					strValue = values[0];
				}
			} else {
				for ( var i = values[1].length; i < intPrecision; i++) {
					strValue += "0";
				}
			}
		} else {
			if (intPrecision > 0) {
				strValue += ".";
				for ( var i = 0; i < intPrecision; i++) {
					strValue += "0";
				}
			}
		}
		obj.val(strValue);
	}

	function cal(changeKey, eleObj) {
		var trNode = eleObj.parent().parent();
		var current_trid = trNode.attr("id");
		var targetEditNode = $('#' + current_trid);

		var taxprice = targetEditNode.find("[name='tax_unit_price']").val();
		var notaxprice = targetEditNode.find("[name='tax_free_unit_price']")
				.val();
		var taxrate = targetEditNode.find("[name='tax_rate']").val();

		// 物料主健
		$("#calpriceform").find("#pk_prod_cal").val(
				targetEditNode.find("[name='pk_prod_v']").val());
		// 报价单位
		$("#calpriceform").find("#pk_unit_cal").val(
				targetEditNode.find("[name='pk_unit']").val());
		// 币种
		$("#calpriceform").find("#pk_currency_cal").val(
				targetEditNode.find("[name='pk_currency']").val());
		// 含税单价
		$("#calpriceform").find("#has_tax_price_cal").val(taxprice);
		// 无税单价
		$("#calpriceform").find("#no_tax_price_cal").val(notaxprice);
		// 税率
		$("#calpriceform").find("#tax_rate_cal").val(taxrate);

		// 共三个字段，当两个为空时不计算
		if (changeKey == "has_tax_price") {
			// 如果当前编辑值被清空，不触发计算
			if (taxprice == null || trim(taxprice) == ""
					|| trim(taxprice) == "null") {
				return;
			} else {
				if ((notaxprice == null || trim(notaxprice) == "" || trim(notaxprice) == "null")
						&& (taxrate == null || trim(taxrate) == "" || trim(taxrate) == "null")) {
					return;
				}
			}
		}
		if (changeKey == "no_tax_price") {
			if (notaxprice == null || trim(notaxprice) == ""
					|| trim(notaxprice) == "null") {
				return;
			} else {
				if ((taxprice == null || trim(taxprice) == "" || trim(taxprice) == "null")
						&& (taxrate == null || trim(taxrate) == "" || trim(taxrate) == "null")) {
					return;
				}
			}
		}
		if (changeKey == "tax_rate") {
			if (taxrate == null || trim(taxrate) == ""
					|| trim(taxrate) == "null") {
				return;
			} else {
				if ((taxprice == null || trim(taxprice) == "" || trim(taxprice) == "null")
						&& (notaxprice == null || trim(notaxprice) == "" || trim(notaxprice) == "null")) {
					return;
				}
			}
		}
		// 触发计算的字段为: changeKey
		$("#calpriceform").find("#property_cal").val(changeKey);
		// 设置参数:无税优先，其他参数不设置，用默认值
		$("#calpriceform").find("#isTaxPrior").val("false");
		var formStr = $('#calpriceform').serialize();
		var bodyContent = $.ajax( {
			url : ebvp_context + "/sourcing/biddingprojlist/calprice",
			type : "POST",
			data : "&" + formStr,
			dataType : "text",
			async : false,
			success : function(responseText) {
				showResponse2(responseText, eleObj);
			}
		})
	}

	function showResponse2(responseText, eleObj) {
		// 0:报价数量|1:税率|2:折扣率|3:含税单价|4:价税合计|5:含税净价|6:主含税净价|7:无税单价|8:无税金额|9:无税净价|10:主无税净价|11:税e|12:行号|13:换算率|14:主数量
		var responseArr = responseText.split("|");
		var index = responseArr[12];

		var trNode = eleObj.parent().parent();
		var current_trid = trNode.attr("id");
		var targetEditNode = $('#' + current_trid);

		// 含税单价
		var hasTaxPrice = targetEditNode.find("[name='tax_unit_price']");
		if (responseArr[3] != null && responseArr[3] != "null"
				&& trim(responseArr[3]) != "") {
			hasTaxPrice.val(responseArr[3]);
		} else {
			hasTaxPrice.val(" ");
		}
		subReduNum(hasTaxPrice, price_digit);

		// 无税单价
		var noTaxPrice = targetEditNode.find("[name='tax_free_unit_price']");
		if (responseArr[7] != null && responseArr[7] != "null"
				&& trim(responseArr[7]) != "") {
			noTaxPrice.val(responseArr[7]);
		} else {
			noTaxPrice.val(" ");
		}
		subReduNum(noTaxPrice, price_digit);

		// 税率
		var taxRate = targetEditNode.find("[name='tax_rate']");
		if (responseArr[1] != null && responseArr[1] != "null"
				&& trim(responseArr[1]) != "") {
			taxRate.val(responseArr[1]);
		} else {
			taxRate.val(" ");
		}
		subReduNum(taxRate, 2);
	}

	function doQueryTaxRate(trNode){
		var pk_prod_v_ele  = trNode.find("[name='pk_prod_v']");
		if(pk_prod_v_ele != null){
			pk_prod_v_val = pk_prod_v_ele.val();
		}
		var myts = new Date();
        jQuery.ajax
        (
            {	
            	type: "GET", 
                async:false, 
               	url:ebvp_context+"/prodprice/queryTaxRateByPkProdV?pk_prod_v="+ pk_prod_v_val +"&myts="+myts, 
               	dataType:"text", 
                success:function(result)
                { 
                	trNode.find("[name='tax_rate']").val(subReduNumPrivate(result,2));                   			                 	
                } 
           	 } 
        ) 
	}
	//txh modified 弹出组织参照
	$("#orgPicked").bind('click', function() {
		//原来组织参照的逻辑
		var items = $("#purOrgHeadPicker").find("[name='pk_purOrg_intree']");
		if(items != null){
			var str="";
			var pks="";
			var pk_groups="";
			for(var loop=0; loop<items.length; loop++){
				if(items[loop].checked == true){					
					str += $(items[loop]).next("label").html();
					pks += $(items[loop]).next("label").next("input").val();	
					pk_groups+=$(items[loop]).next("label").next("input").next("input").val() ;
					break;
				}
			}
			if(str != ""){
				$("#qryPurOrg").val(str).attr("style", "color:black");			
			}
			$("#pk_purOrg").val(pks);
			$("#pk_group").val(pk_groups);
		}
		
		//ajax查询物料分类的逻辑
			var prodCateJson = "";
			var myts = new Date();
			jQuery.ajax( {
							type : "GET",
							async : false,
							url : ebvp_context
									+ "/prodprice/addprod?myts="
									+ myts,
							dataType : "text",
							success : function(result) {
								prodCateJson = result;
							}
						})
						
						if(prodCateJson == ""){
							return;
						}
					
						var prodCateArr = eval(prodCateJson);
						var htmlInTreeList = "";
						for ( var loop = 0; loop < prodCateArr.length; loop++) {
							var pkProdCate = prodCateArr[loop].pkProdCate;
							var prodCateCode = prodCateArr[loop].prodCateCode;
							var prodCateName = prodCateArr[loop].prodCateName;
							htmlInTreeList += "<div class=\"tree_category\"><a class=\"category_trigger\"></a><input id=\"category"
									+ (loop + 1)
									+ "\" type=\"checkbox\" value=\""
									+ pkProdCate
									+ "\" disabled /><label for=\"category"
									+ (loop + 1)
									+ "\">"
									+ prodCateName
									+ "</label></div>";
						}

						$(".tree_list").html(htmlInTreeList);						
						$("#prodPkChecked").empty();
						$("#purOrgHeadPicker").slideUp();
		return false;
	});
	
	//弹出产品树-添加产品
	var addProdFunction = function() {
		$("#addProdBtn").bind("click", function() {
			var position = $("#addProdBtn").offset();
				position.top += 20;
				//$("#qryPurOrg").empty();				
				$("#qryPurOrg").attr("value","");
				$("#productPicker").slideDown();
				$("#productPicker").offset(position);
				$("#prod_tree").empty();	
			return false;		
		});
	
		$("#productCancel").live('click', function() {
			$("#productPicker").slideUp();
			return false;
		});
		//选择产品 ，点加号触发的事件
		$(".category_trigger")
				.live('click', function() {
						var trigger = $(this);
						if(trigger.hasClass("close")){
							trigger.parent(".tree_category").next(".tree_items").slideUp(function(){
								trigger.removeClass("close");
							});
							return false;
						}
						
					    // 通过ajax调用后台取到产品的数据
						// 产品分类：
						var prodJson = "";
						var prodCatePk = $(this).next("input").val();
						var pkOrg = $('#pk_purOrg').val();
						var myts = new Date();    	
			            jQuery
								.ajax( {
									type : "GET",
									async : false,
									url : ebvp_context
											+ "/prodprice/qryProdByProdcatePk?prodCatePk="
											+ prodCatePk + "&pkOrg="+pkOrg+"&myts=" + myts,
									dataType : "text",
									success : function(result) {
										prodJson = result;
									}
								});
						
						// var prodJson =
						// "[{\"pkProdv\":\"1001ZF1000000000V566\",
						// \"prodName\":\"分类1物料1\"},
						// {\"pkProdv\":\"1001ZF1000000000W4N4\",
						// \"prodName\":\"分类1物料2\"}]";
			            if(prodJson == ""){
			            	return;
			            }
			            
						var prodArr = eval(prodJson);
						
						
//						var prodStr = "<div class=\"tree_items\">";
//						for ( var loop = 0; loop < prodArr.length; loop++) {
//							var pkProdv = prodArr[loop].pk_prod_v;
//							var prodName = prodArr[loop].prod_name;
//							var prodModule = prodArr[loop].prod_module;
//							var prodType = prodArr[loop].prod_type;
//							prodStr += "<div class=\"tree_item\"><div class=\"float_left w_216px\">"
//									+ " <input id=\"product_"
//									+ (loop + 1)
//									+ "\" type=\"checkbox\" value=\""
//									+ pkProdv
//									+ "\"/> <label for=\"product_"
//									+ (loop + 1)
//									+ "\">"
//									+ prodName
//									+ "</label>"
//									+ "</div><div class=\"float_left w_120px\">"+prodModule+"</div><div class=\"float_left w_66px\">"+prodType+"</div></div>";
//						}
//						prodStr += "</div>";
						
						//用jquery对象组织节点，而不是用html拼接
						var treeItemsDiv = $("<div></div>").addClass("tree_items");
						for ( var loop = 0; loop < prodArr.length; loop++) {
							var pkProdv = prodArr[loop].pk_prod_v;
							var prodName = prodArr[loop].prod_name;
							var prodModule = prodArr[loop].prod_module;
							var prodType = prodArr[loop].prod_type;
							
							var treeItemDiv = $("<div></div>").addClass("tree_item");
							
							var floatDiv = $("<div></div>").addClass("float_left").addClass("w_126px");
							var inputPid = $("<input></input>").val(pkProdv).attr("type","hidden");  //在checkbox之前隐藏一个input，记录主键
							var checkboxDiv = $("<input></input>").attr("id", "product_" + (loop+1)).attr("type", "checkbox").val(pkProdv).attr("name", "pkProdCheckbox");
							var labelDiv = $("<label></label>").attr("for", "product_"+(loop+1)).text(prodName);
							floatDiv.append(inputPid).append(checkboxDiv).append(labelDiv);
							
							var floatLeftModuleDiv = $("<div></div>").addClass("float_left").addClass("w_126px").text(prodModule);
							var floatLeftTypeDiv = $("<div></div>").addClass("float_left").addClass("w_126px").text(prodType);
							
							treeItemDiv.append(floatDiv).append(floatLeftModuleDiv).append(floatLeftTypeDiv);
							
							treeItemsDiv.append(treeItemDiv);
							
							//展开时判断，每个产品，如果已经选过，
							var inputs = $("#prodPkChecked").find("input");
							for(var loopJ=0; loopJ < inputs.length; loopJ++){
								if($(inputs[loopJ]).val() == pkProdv){
									$(treeItemDiv.find("[type='checkbox']")[0]).attr("checked", "checked");
								}
							}
						}
						
						//加之前清空一下原来的
						$(this).parent().after(treeItemsDiv);
						
						var self = this;
						var items = $(this).parents(".tree_category").next(
								".tree_items");
						$(".tree_items").not(items).slideUp(
								function() {
									$(this).prev(".tree_category").find(
											".category_trigger").removeClass("close");
						});
						if (items.is(":hidden"))
							items.slideDown(function() {
								$(self).addClass("close");
							});
						else
							items.slideUp(function() {
								$(self).removeClass("close");
							});

						return false;
					});

		function valInProdPkChecked(val){
			var reallyCheckedPkInputs = $("#prodPkChecked").find("input");
			for(var loop=0; loop<reallyCheckedPkInputs.length; loop++){
				var tempVal = $(reallyCheckedPkInputs[loop]).val();
				if(tempVal == val){
					return true;
				}
			}
			return false;
		}
		//往产品c输入产品信息
		$(".tree_btns .idBtnPicked")
				.live(
						'click',
						function() {
							//var temp_items = $(this).parents(".ui-drop_dialog").find("input:checked");
							var temp_items = $("#prod_tree").find("input:checked");
							
							var items = new Array();
							for(var loop=0; loop<temp_items.length; loop++){
								var val = $(temp_items[loop]).val();
								var kk = 0;
								for(kk =0; kk<items.length; kk++){
									var tempV = $(items[kk]).val();
									if(tempV == val){
										break;
									};
								}
								if(kk == items.length && valInProdPkChecked(val)){
									items.push(temp_items[loop]);
								};								
							}
							
							
							$(this).parents(".ui-drop_dialog").slideUp();

							var maxNO = ($("#prodListTable").find("tr").size() - 1) / 2; // 添加产品分类之前，表中存在的最大序号值
							var NO_increase = 1; // 序号增量
							var org_name = $('#qryPurOrg').val();	
							var pkOrg = $('#pk_purOrg').val();	
							for ( var loop = 0; loop < items.length; loop++) {
								var prodCatePk = $(items[loop]).parents(
										".tree_items").prev(".tree_category")
										.find("input:checkbox").val();
								var pkProdv = $(items[loop]).val();
								var prodName = $(items[loop]).next("label")
										.html();
								var prodModule = $(items[loop]).parent().next(
										".float_left").html();
								var prodType = $(items[loop]).parent().next(
										".float_left").next(".float_left")
										.html();

								// 序号
								var current_NO = Math
										.floor(Math.random() * 10000000000000000000);// maxNO
																						// +
																						// NO_increase;
								NO_increase = NO_increase + 1;
								
								var tax_unit_price_id = "tax_unit_price" + current_NO;
								var tax_free_unit_price_id = "tax_free_unit_price" + current_NO;
								var tax_rate_id = "tax_rate" + current_NO;
								var valid_date_id = "valid_date" + current_NO;
								var invalid_date_id = "invalid_date"
										+ current_NO;

								if ((maxNO + NO_increase) % 2 == 0) {
									var editRowFormStr = "<tr id='trid_"
											+ current_NO
											+ "'  targetid='hide_trid_"
											+ current_NO
											+ "' class='contTr-even' >";
								} else {
									var editRowFormStr = "<tr id='trid_"
											+ current_NO
											+ "'  targetid='hide_trid_"
											+ current_NO
											+ "' class='contTr-old' >";
								}
								editRowFormStr += "<td class='checkboxCol'><input type='checkbox' name='isCommited' value=''/></td>";
								editRowFormStr += "<td> "
								if (org_name != null && trim(org_name) != ""
										&& trim(org_name) != "null") {
									editRowFormStr += "<span>"
											+ org_name + "</span>";
											+ "<br/> <span>"
											+ pkOrg + " type='hidden' </span>"
								}
								editRowFormStr += "</td> <td>"
								if (prodName != null && trim(prodName) != ""
										&& trim(prodName) != "null") {
									editRowFormStr += "<span>"
											+ prodName + "</span>";
								}
								editRowFormStr += "</td> "
								if (prodModule != null
										&& trim(prodModule) != ""
										&& trim(prodModule) != "null") {
									editRowFormStr += "<br/><span id='hide_module'>"+getLanMsg("0ec22200-000021")+""
											+ prodModule + "</span>";
								}
								if (prodType != null && trim(prodType) != ""
										&& trim(prodType) != "null") {
									editRowFormStr += "<br/><span id='hide_type'>"+getLanMsg("0ec22200-000022")+""
											+ prodType + "</span>";
								}
								editRowFormStr += "</td>";
								editRowFormStr += "<td>"+getLanMsg("0ec22200-000023")+"<select name='pk_unit' ></select><br/>"+getLanMsg("0ec22200-000024")+"<select name='pk_currency' /></td>"
										+ "<td><span>"+getLanMsg("0ec22200-000025")+"</span><input name='tax_unit_price' id='"+tax_unit_price_id+"'  type='text' class='prod_textfield w_66px' /><br/><span>"+getLanMsg("0ec22200-000026")+"</span><input name='tax_free_unit_price' id='"+tax_free_unit_price_id+"'  type='text' class='prod_textfield w_66px' /><br/><span style='visibility:hidden'>"+getLanMsg("0ec22200-000073")+"</span><span>"+getLanMsg("0ec22200-000027")+"</span><input  name='tax_rate' id='"+tax_rate_id+"' type='text' class='prod_textfield w_66px' /></td>";
								editRowFormStr += "<td><span class='float_left'>"+getLanMsg("0ec22200-000028")+"</span><input name='valid_date' id='"
										+ valid_date_id
										+ "' type='text'  class='textfieldnew pd_5x2px datepicker' data-datepicker-onSelect='window.onDatePickerSelect(this)' sytle='width:88px' /><br/><span style='float:left'>"+getLanMsg("0ec22200-000029")+"</span><input name='invalid_date' id='"
										+ invalid_date_id
										+ "' type='text'  class='textfieldnew pd_5x2px datepicker' data-datepicker-onSelect='window.onDatePickerSelect(this)' sytle='width:88px'  /></td>";
								editRowFormStr += "<td>"+getLanMsg("0ec22200-000030")+"<select name='pk_manufactory' ></select><br/>";
								editRowFormStr += ""+getLanMsg("0ec22200-000031")+"<select name='pk_transport_type' ></select></td>";
								editRowFormStr += "<td><a name='saveProdBtn' ><span class='saveLink'></span></a><a name='deleteProdBtn'><span class='deleteLink'></span></a>";
								editRowFormStr += "<input name='primaryKey' type='hidden' />";
								editRowFormStr += "<input name='prod_cate_pk'  type='hidden' value='"
										+ prodCatePk + "' />";
								editRowFormStr += "<input name='pk_prod_v'  type='hidden' value='"
										+ pkProdv + "' /> </td>";
								editRowFormStr += "</tr>";

								// 区分
								if ((maxNO + NO_increase) % 2 == 0) {
									var hideRowStr = "<tr id='hide_trid_"
											+ current_NO
											+ "' targetid='trid_"
											+ current_NO
											+ "'  class='contTr-even' style='display: none;'>";
								} else {
									var hideRowStr = "<tr id='hide_trid_"
											+ current_NO
											+ "'  targetid='trid_"
											+ current_NO
											+ "' class='contTr-old' style='display: none;'>";
								}
								hideRowStr += "<td class='checkboxCol'><input type='checkbox' name='isCommited' value='' /></td>";
								hideRowStr += "<td>";
								if (org_name != null && trim(org_name) != ""
										&& trim(org_name) != "null") {
									hideRowStr += "<span>"
											+ org_name + "</span>";
											+ "<br/> <span>"
											+ pkOrg + " type='hidden' </span>"
								}
								hideRowStr += "</td> <td>"
								if (prodName != null && trim(prodName) != ""
										&& trim(prodName) != "null") {
									hideRowStr += "<span>"
											+ prodName + "</span>";
								}
								if (prodModule != null
										&& trim(prodModule) != ""
										&& trim(prodModule) != "null") {
									hideRowStr += "<br/><span title='hide_module'>"+getLanMsg("0ec22200-000021")+""
											+ prodModule + "</span>";
								}
								if (prodType != null && trim(prodType) != ""
										&& trim(prodType) != "null") {
									hideRowStr += "<br/><span title='hide_type'>"+getLanMsg("0ec22200-000022")+""
											+ prodType + "</span>";
								}
								hideRowStr += "</td>";
								hideRowStr += "<td><span title='hide_unit'>"+getLanMsg("0ec22200-000023")+"</span><br/><span title='hide_currency_name'>"+getLanMsg("0ec22200-000024")+"</span></td>";
								hideRowStr += "<td><span>"+getLanMsg("0ec22200-000025")+"</span><span title='hide_tax_unit_price'></span><br/><span>"+getLanMsg("0ec22200-000026")+"</span><span title='hide_tax_free_unit_price' ></span><br/><span style='visibility:hidden'>"+getLanMsg("0ec22200-000073")+"</span><span>"+getLanMsg("0ec22200-000027")+"</span><span title='hide_tax_rate' ></span></td>";
								hideRowStr += "<td>"+getLanMsg("0ec22200-000028")+"<span title='hide_valid_date'></span><br/>"+getLanMsg("0ec22200-000029")+"<span title='hide_invalid_date'></span></td>";
								hideRowStr += "<td><span title='hide_manufactory_name'>"+getLanMsg("0ec22200-000030")+"</span><br/>";
								hideRowStr += "<span title='hide_transport_type'>"+getLanMsg("0ec22200-000031")+"</span></td>";
								hideRowStr += "<td><a name='modifyProdBtn'><span class='modifyLink' ></span></a><a name='deleteProdBtn'><span class='deleteLink'></span></a></td>";
								hideRowStr += "</tr>";

								$('#productListTable').append(editRowFormStr);
								$('#productListTable').append(hideRowStr);

								var trNode = "#trid_" + current_NO;
								
								seajs.use(['jquery','jquery.ui.datepicker'],function($,datepicker){
									$ = datepicker($);
								});
								
								// 查询税率
								doQueryTaxRate($(trNode));

								// 初始化 单位和生产厂商
								initUnitAndManufacure($(trNode));

								// 初始化 币种
								initCurrency($(trNode));

								// 初始化 运输方式
								initTransport($(trNode));
							}
							$("#productPicker").slideUp();
							return false;
						});
		$(".tree_btns .idBtnCancel").live('click', function() {
			$(this).parents(".ui-drop_dialog").slideUp();
			return false;
		});
		
	}

	this.init = function() {

		initPriceDigit();

		queryFunction();

		cancelFunction();

		//lastPageFunction();

		//nextPageFunction();

		//nPageFunction();

		addProdFunction();

		//这里是为了合上之后再展开，之前勾选过的产品还打着勾
		$("body").delegate("[name='pkProdCheckbox']", 'click', function(){
			//this:是一个checkbox,IE10中,checkbox的值为on/off;而不是实际的val;
			//为兼容IE10,在checkbox前隐藏了一个input,值为所选主键,所以这里用$(this).prev().val();
			var val = $(this).prev().val();
			if($(this).attr("checked") == "checked"){
				var name = $(this).next("label").text();
				$("#prodPkChecked").append($("<input></input>").attr("id", val).val(val).attr("type","hidden").attr("prodname", name));
			}else{
				$("#"+val).remove();
			}
		});
		
		$("body").delegate(".numType", "blur", function() {
			validatorData($(this));
		});

		// 修改
		$("body").delegate("[name='modifyProdBtn']",
				'click',
				function() {
					var trNode = $(this).parents("tr");
					var current_trid = trNode.attr("id");
					var target_trid = trNode.attr("targetid");
					var targetEditNode = $('#' + target_trid);

					initUnitAndManufacure(targetEditNode);
					initCurrency(targetEditNode);
					initTransport(targetEditNode);

					// 隐藏浏览行
					$('#' + target_trid).show();
					if ($('#' + current_trid).find("[name='isCommited']").attr(
							"checked") == true) {
						$('#' + current_trid).find("[name='isCommited']").attr(
								"checked", "");
					}
					$('#' + current_trid).hide();
			});
		
		// 删除
		$("body").delegate(
				"[name='deleteProdBtn']",
				'click',
				function() {
					var that = $(this);
					var option = {
						title : getLanMsg("0ec22200-000051"),
						content : getLanMsg("0ec22200-000052"),
						confirm : function() {
							var trNode = that.parents("tr");
							var current_trid = trNode.attr("id");
							var target_trid = trNode.attr("targetid");
							var targetEditNode = $('#' + target_trid);

							// 先删除界面数据,删除前先把pk记录下来
							var pk = $(
									targetEditNode.find("[name='primaryKey']")[0])
									.val();
							$("#" + current_trid).remove();
							$("#" + target_trid).remove();
	
							// 如果pk有值，说明此为后台查询出来的数据，也要删除后台数据
							var myts = new Date();
							if (pk != null) {
								$.ajax( {
									url : ebvp_context
											+ "/prodprice/deletePrice?myts=" + myts
											+ "&pk=" + pk,
									type : "GET",
									dataType : "text",
									async : false,
									success : function(msg) {
										$("#error_img").remove();
										$("#error_span").remove();
										
										var path = ebvp_context + "/commonres/common/frame/src/img/img_success.png" 
										var img = $("<img></img>").attr("src", path).attr("style","float:right").attr("id","error_img");
										var span = $("<span></span>").text(getLanMsg("0ec22200-000053")).addClass("prod_error_span").attr("id", "error_span");
										
										span.insertAfter("#batchDeleteProdBtn");
										img.insertAfter("#error_span");
									},
									error:function(msg){
										$("#error_img").remove();
										$("#error_span").remove();
										
										var path = ebvp_context + "/commonres/common/frame/src/img/img_error.png" 
										var img = $("<img></img>").attr("src", path).attr("style","float:right").attr("id","error_img");
										var span = $("<span></span>").text(getLanMsg("0ec22200-000054")).addClass("prod_error_span").attr("id", "error_span");
										
										span.insertAfter("#batchDeleteProdBtn");
										img.insertAfter("#error_span");
									}
								})
							}
							return true;
						}
					}
					showConfirmDialog(option);
					return false;
				});
		
		// 保存
		$("body")
				.delegate("[name='saveProdBtn']", 'click', function() {
					var formNode = $(this).parents("tr");
					
					// 校验第一步：含税单价，无税单价，税率，生效日期，失效日期 必填,且符合数据格式
					// 含税单价
					checkNumField(formNode, "tax_unit_price");
					// 无税单价
					checkNumField(formNode, "tax_free_unit_price");
					// 税率
					checkNumField(formNode, "tax_rate");
					// 生效日期
					checkDateField(formNode, "valid_date");
					// 失效日期
					checkDateField(formNode, "invalid_date");
					if (formNode.find(".error").length > 0) {
						return ;
					}
						
					//校验第二步：生效日期、失效日期是否合法
					var ErrMsg = "";
					var vDate = $(formNode.find("input[name='valid_date']")[0]).val().replace("-", "/").replace("-", "/");
					var invDate = $(formNode.find("input[name='invalid_date']")[0]).val().replace("-", "/").replace("-", "/");
					var date1 = new Date(Date.parse(vDate));
					var date2 = new Date(Date.parse(invDate));
					formNode.find("[for='date']").remove();
					if(date1 > date2){
						ErrMsg =getLanMsg("0ec22200-000072");
						var errLabel = $("<label></label>").addClass("error").attr("for", "date").attr("title", ErrMsg)
						    .attr("style", "display: inline; width: 18px; height: 18px; left:930px");
						errLabel.insertAfter($(formNode.find("input[name='invalid_date']")[0]));
						return;
					}
					if(ErrMsg != ""){
						return;
					}
						
					    // 61时每行tr外面都套有一个form，然后将form
						// 序列化，则得到json串；
						// 但有些浏览器不支持大form套小form(整体是个form,每行又是个form)
						// 所以，取消小form，设法找到每行的各个元素的值，手动拼接成json串
						var saveBtn = $(this);
						
						var jsonStr = "";
						$(this).parent().parent().find("input").each(
								function() {
									if ($(this).attr("name") != "isCommited") {
										jsonStr += $(this).attr("name") + "="
												+ $(this).val() + "&";
									}
						});
						$(this).parent().parent().find("input").each(
								function() {
									if ($(this).attr("name") != "isCommited") {
										jsonStr += $(this).attr("name") + "="
												+ $(this).val() + "&";
									}
								});
						$(this).parent().parent().find("select").each(
								function() {
									jsonStr += $(this).attr("name") + "="
											+ $(this).val() + "&";
								});
						jsonStr = jsonStr.substring(0, jsonStr.length - 1);
						//json里传入组织ｐｋ
						jsonStr+="&pk_org="+$(this).parents("tr").find("input[name='pk_Org']").val();
						var bodyContent = $
								.ajax( {
									url : ebvp_context
											+ "/prodprice/submitprice",
									type : "POST",
									data : "&" + jsonStr,
									dataType : "text",
									async : false,
									success : function(msg) {
										if (msg == 'NULL') {
											
											$("#error_img").remove();
											$("#error_span").remove();
											
											var path = ebvp_context + "/commonres/common/frame/src/img/img_error.png";
											var img = $("<img></img>").attr("src", path).attr("style","float:right").attr("id","error_img");
											var span = $("<span></span>").text(getLanMsg("0ec22200-000055")).addClass("prod_error_span").attr("id", "error_span");
											
											span.insertAfter("#batchDeleteProdBtn");
											img.insertAfter("#error_span");
										}else if(msg!= null && msg.indexOf("ERROR-:-")>-1){
											$("#error_img").remove();
											$("#error_span").remove();
											var path = ebvp_context + "/commonres/common/frame/src/img/img_error.png";
											var img = $("<img></img>").attr("src", path).attr("style","float:right").attr("id","error_img");
											var span = $("<span></span>").html(msg.substring(8)).addClass("prod_error_span").attr("id", "error_span");
											
											span.insertAfter("#batchDeleteProdBtn");
											img.insertAfter("#error_span");
										}else {
											$("#error_img").remove();
											$("#error_span").remove();
											
											var path = ebvp_context + "/commonres/common/frame/src/img/img_success.png"; 
											var img = $("<img></img>").attr("src", path).attr("style","float:right").attr("id","error_img");
											var span = $("<span></span>").text(getLanMsg("0ec22200-000056")).addClass("prod_error_span").attr("id", "error_span");
											
											span.insertAfter("#batchDeleteProdBtn");
											img.insertAfter("#error_span");

											var trNode = saveBtn.parent()
													.parent();
											var current_trid = trNode
													.attr("id");
											var target_trid = trNode
													.attr("targetid");
											$('#' + target_trid).show();
											if ($('#' + current_trid).find(
													"[name='isCommited']")
													.attr("checked") == true) {
												$('#' + current_trid).find(
														"[name='isCommited']")
														.attr("checked", "");
											}
											$('#' + current_trid).hide();

											// 刷新浏览行
											var retValueArray = msg.split("|");
											//组织
											$('#' + target_trid).find(
													"[name='org_name']").val(
													retValueArray[0]);
													
											$('#' + current_trid).find(
													"[name='primaryKey']").val(
													retValueArray[17]);
											$('#' + current_trid).find(
													"[name='isCommited']").val(
													retValueArray[17]);
											$('#' + target_trid).find(
													"[name='isCommited']").val(
													retValueArray[17]);

											if (retValueArray[5] != null
													&& retValueArray[5] != "null"
													&& trim(retValueArray[5])) {
												$('#' + target_trid)
														.find(
																"[title='hide_unit']")
														.text(
																getLanMsg("0ec22200-000036")
																		+ retValueArray[5]);
											} else {
												$('#' + target_trid).find(
														"[title='hide_unit']")
														.text("");
											}
											if (retValueArray[7] != null
													&& retValueArray[7] != "null"
													&& trim(retValueArray[7])) {
												$('#' + target_trid)
														.find(
																"[title='hide_currency_name']")
														.text(
																getLanMsg("0ec22200-000037")
																		+ retValueArray[7]);
											}
											$('#' + target_trid)
													.find(
															"[title='hide_tax_unit_price']")
													.html(retValueArray[8]);
											$('#' + target_trid)
													.find(
															"[title='hide_tax_free_unit_price']")
													.html(retValueArray[9]);
											$('#' + target_trid)
													.find(
															"[title='hide_tax_rate']")
													.html(subReduNumPrivate(retValueArray[10],2));
											$('#' + target_trid)
													.find(
															"[title='hide_valid_date']")
													.html(retValueArray[11]);
											$('#' + target_trid)
													.find(
															"[title='hide_invalid_date']")
													.html(retValueArray[12]);

											if (retValueArray[14] != null
													&& retValueArray[14] != "null"
													&& trim(retValueArray[14])) {
												$('#' + target_trid)
														.find(
																"[title='hide_manufactory_name']")
														.html(
																getLanMsg("0ec22200-000030")
																		+ retValueArray[14]);
											} else {
												$('#' + target_trid)
														.find(
																"[title='hide_manufactory_name']")
														.html("");
											}
											if (retValueArray[16] != null
													&& retValueArray[16] != "null"
													&& trim(retValueArray[16])) {
												$('#' + target_trid)
														.find(
																"[title='hide_transport_type']")
														.html(
																getLanMsg("0ec22200-000031")
																		+ retValueArray[16]);
											} else {
												$('#' + target_trid)
														.find(
																"[title='hide_transport_type']")
														.html("");
											}
										}
									}
								})

					});

		// 含税单价
		$("body").delegate("[name='tax_unit_price']", "change", function() {
			checkNumField($(this).parents("tr"), "tax_unit_price");
			
			subReduNum($(this), price_digit);
			cal("has_tax_price", $(this));
			
			checkNumField($(this).parents("tr"), "tax_free_unit_price");
			checkNumField($(this).parents("tr"), "tax_rate");
		});
		// 无税单价
		$("body").delegate("[name='tax_free_unit_price']", "change",
				function() {
			checkNumField($(this).parents("tr"), "tax_free_unit_price");
		
			subReduNum($(this), price_digit);
			cal("no_tax_price", $(this));
			
			checkNumField($(this).parents("tr"), "tax_unit_price");
			checkNumField($(this).parents("tr"), "tax_rate");
		});
		// 税率
		$("body").delegate("[name='tax_rate']", "change", function() {
			checkNumField($(this).parents("tr"), "tax_rate");
			
			subReduNum($(this), price_digit);
			cal("tax_rate", $(this));
			
			checkNumField($(this).parents("tr"), "tax_unit_price");
			checkNumField($(this).parents("tr"), "tax_free_unit_price");
		});
		
//		// 含税单价
//		$("body").delegate("[name='tax_unit_price']", "keyup", function() {
//			checkNumField($(this).parents("tr"), "tax_unit_price");
//			
//			subReduNum($(this), price_digit);
//			cal("has_tax_price", $(this));
//			
//			checkNumField($(this).parents("tr"), "tax_free_unit_price");
//			checkNumField($(this).parents("tr"), "tax_rate");
//		});
//		// 无税单价
//		$("body").delegate("[name='tax_free_unit_price']", "keyup",
//				function() {
//			checkNumField($(this).parents("tr"), "tax_free_unit_price");
//			
//			subReduNum($(this), price_digit);
//			cal("no_tax_price", $(this));
//			
//			checkNumField($(this).parents("tr"), "tax_unit_price");
//			checkNumField($(this).parents("tr"), "tax_rate");
//		});
//		// 税率
//		$("body").delegate("[name='tax_rate']", "keyup", function() {
//			checkNumField($(this).parents("tr"), "tax_rate");
//			
//			subReduNum($(this), price_digit);
//			cal("tax_rate", $(this));
//			
//			checkNumField($(this).parents("tr"), "tax_unit_price");
//			checkNumField($(this).parents("tr"), "tax_free_unit_price");
//		});
		
		
		//删除
		$("body").delegate("#batchDeleteProdBtn", "click", function() {
			var isCommitedArray = $("[name='isCommited']");
			for ( var i = 0; i < isCommitedArray.length; i++) {
				if (isCommitedArray[i].checked == true) {
					break;
				}
			}
			if (i == isCommitedArray.length) {
				showCfmMsg(getLanMsg("0ec22200-000051"), getLanMsg("0ec22200-000074"));
				return;
			}

			var option = {
					title : getLanMsg("0ec22200-000051"),
					content : getLanMsg("0ec22200-000057"),
					confirm : function() {
						var formStr = $('#productListForm').serialize();
						var bodyContent = $.ajax( {
							url : ebvp_context + "/prodprice/deletePriceBatch",
							type : "POST",
							data : "&" + formStr,
							dataType : "text",
							async : false,
							success : function(msg) {
							}
						});
						for ( var x = 0; x < isCommitedArray.length; x++) {
							if (isCommitedArray[x].checked == true) {
								$(isCommitedArray[x]).parents("tr").remove();
							}
						}
						return true;
					}
			};
			showConfirmDialog(option);
			//var b = showConfirmDialog(getLanMsg("0ec22200-000051"),getLanMsg("0ec22200-000057"));
//			if (b == true) {
//				var formStr = $('#productListForm').serialize();
//				var bodyContent = $.ajax( {
//					url : ebvp_context + "/prodprice/deletePriceBatch",
//					type : "POST",
//					data : "&" + formStr,
//					dataType : "text",
//					async : false,
//					success : function(msg) {
//					}
//				})
//				for ( var x = 0; x < isCommitedArray.length; x++) {
//					if (isCommitedArray[x].checked == true) {
//						$(isCommitedArray[x]).parents("tr").remove();
//					}
//				}
//			} else {
//				return;
//			}
		});

		$("body").delegate(
				"#exportProdBtn",
				'click',
				function() {
					var isCommitedArray = $("[name='isCommited']");
					for ( var i = 0; i < isCommitedArray.length; i++) {
						if (isCommitedArray[i].checked == true) {
							break;
						}
					}
					if (i == isCommitedArray.length) {
						showCfmMsg(getLanMsg("0ec22200-000051"), getLanMsg("0ec22200-000058"));
						return;
					} else {
						 var arr =  $("body").find("[name='primaryKey']");
						 for(var x = 0; x<arr.length; x++){
							 var isChecked = $(arr).parents("tr").find("[name='isCommited']")[0].checked;
							 if( (arr[x].value == "" || arr[x].value == null) && isChecked == true ){
								 showCfmMsg(getLanMsg("0ec22200-000051"), getLanMsg("0ec22200-000075"));
								 return ;
							 }
						 } 
						 
						$("#productListForm").attr("action",
								ebvp_context + "/prodprice/export2xls");
						$("#productListForm").submit();
					}
				});
			 
	};
}


$(function() {
	var prodpriceMaintain = new ProdpriceMaintain();
	prodpriceMaintain.init();
});

function checkNumField(trNode, fieldName){
	var requiredStr = getLanMsg("0ec22200-000070");
	var numberFormatStr = getLanMsg("0ec22200-000071");
	trNode.find("[for='"+fieldName+"']").remove();
	var jUnitPriceObj = $(trNode.find("input[name='"+fieldName+"']")[0]);
	var jUnitPriceErrLabel = $("<img></img>")
					.addClass("error")
					.attr("for", fieldName)
					.attr("src",
					"/ebvp/commonres/common/frame/src/img/validate_error.png");
	if (jUnitPriceObj.val() == null || trim(jUnitPriceObj.val()) == "") {
		jUnitPriceErrLabel.attr("title", requiredStr);
		jUnitPriceErrLabel.insertAfter(jUnitPriceObj);
	}else{
		if(isNaN(jUnitPriceObj.val())){
			jUnitPriceErrLabel.attr("title", numberFormatStr);
			jUnitPriceErrLabel.insertAfter(jUnitPriceObj);
    	}
	}
}

function checkDateField(trNode, fieldName){
	var requiredStr = getLanMsg("0ec22200-000070");
	trNode.find("[for='"+fieldName+"']").remove();
	var jUnitPriceObj = $(trNode.find("input[name='"+fieldName+"']")[0]);
	var jUnitPriceErrLabel = $("<img></img>")
					.addClass("error")
					.attr("for", fieldName)
					.attr("src",
					"/ebvp/commonres/common/frame/src/img/validate_error.png");
	if (jUnitPriceObj.val() == null || trim(jUnitPriceObj.val()) == "") {
		jUnitPriceErrLabel.attr("title", requiredStr);
		jUnitPriceErrLabel.insertAfter(jUnitPriceObj);
	}
}

//日期发生变更时，校验生效日期和失效日期的大小
window.onDatePickerSelect = function(obj){
	var formRow = $(obj).parents("tr");
	var vDate = $(formRow.find("input[name='valid_date']")[0]).val().replace("-", "/").replace("-","/");
	var invDate = $(formRow.find("input[name='invalid_date']")[0]).val().replace("-", "/").replace("-","/");
	var date1 = new Date(Date.parse(vDate));
	var date2 = new Date(Date.parse(invDate));
	
	checkDateField(formRow, $(obj).attr("name"));
	if(formRow.find("[for='valid_date']").length > 0 ){
		return ;
	}
	if(formRow.find("[for='invalid_date']").length > 0 ){
		return ;
	}
	
	formRow.find("[for='date']").remove();
	if(date1 > date2){
		ErrMsg =getLanMsg("0ec22200-000072");
		if(formRow.find("[for='date']").length == 0){
			var errLabel = $("<img></img>").addClass("error").attr("for", "date").attr("title", ErrMsg)
				.attr("src", "/ebvp/commonres/common/frame/src/img/validate_error.png");
			errLabel.insertAfter($(obj));
		}
		return;
	}
}